; Assemble with:
;aasm s.Largeness Largeness -M -Q

                GET     Hdr.regs
                GET     Hdr.swis

start           DCD     0
                DCD     init-start
                DCD     0
                DCD     service-start
                DCD     myname-start
                DCD     mytitle-start
                DCD     myhelp-start
                DCD     Wimp_Initialise
                DCD     myswi-start
                DCD     switable-start
                DCD     0
myname          DCB     "Largeness",0
mytitle         DCB     "Largeness",9,"2.00 (10 Aug 1991) by BDB",0
myhelp          DCB     "Largeness",0
                ALIGN
                DCD     0
                DCD     0
                DCD     0
                DCD     myhelptxt-start
                DCD     0
myhelptxt       DCB     "This module patches the WIMP so all windows are no bounds.",0
switable
        =       "Wimp",0
        =       "Initialise",0
        =       "CreateWindow",0
        =       "CreateIcon",0
        =       "DeleteWindow",0
        =       "DeleteIcon",0
        =       "OpenWindow",0
        =       "CloseWindow",0
        =       "Poll",0
        =       "RedrawWindow",0
        =       "UpdateWindow",0
        =       "GetRectangle",0
        =       "GetWindowState",0
        =       "GetWindowInfo",0
        =       "SetIconState",0
        =       "GetIconState",0
        =       "GetPointerInfo",0
        =       "DragBox",0
        =       "ForceRedraw",0
        =       "SetCaretPosition",0
        =       "GetCaretPosition",0
        =       "CreateMenu",0
        =       "DecodeMenu",0
        =       "WhichIcon",0
        =       "SetExtent",0
        =       "SetPointerShape",0
        =       "OpenTemplate",0
        =       "CloseTemplate",0
        =       "LoadTemplate",0
        =       "ProcessKey",0
        =       "CloseDown",0
        =       "StartTask",0
        =       "ReportError",0
        =       "GetWindowOutline",0
        =       "PollIdle",0
        =       "PlotIcon",0
        =       "SetMode",0
        =       "SetPalette",0
        =       "ReadPalette",0
        =       "SetColour",0
        =       "SendMessage",0
        =       "CreateSubMenu",0
        =       "SpriteOp",0
        =       "BaseOfSprites",0
        =       "BlockCopy",0
        =       "SlotSize",0
        =       "ReadPixTrans",0
        =       "ClaimFreeMemory",0
        =       "CommandWindow",0
        =       "TextColour",0
        =       "TransferBlock",0
        =       "ReadSysInfo",0
        =       "SetFontColours",0
        =       "GetMenuState",0
        =       0
wimpname        DCB     "WindowManager",0

                ^       0,R12
wimppriv        #       4
wimpentry       #       4
screen_maxx     #       4
screen_maxy     #       4
workspacesize   *       :INDEX: @

                ALIGN

init            STMDB   R13!,{R14}
                MOV     R0,#6   ;Claim
                MOV     R3,#workspacesize
                SWI     XOS_Module
                LDMVSIA R13!,{PC}
                STR     R2,[R12]
                MOV     R12,R2
                BL      read_screen_size
                MOV     R0,#18  ;Look up module name
                ADR     R1,wimpname
                SWI     XOS_Module
                LDMVSIA R13!,{PC}
                LDR     R5,[R3,#&20]
                ADD     R5,R5,R3
                STMIA   R12,{R4,R5}     ;priv word,entry pt
                LDMIA   R13!,{PC}

service         TEQ     r1,#&27                 ; see if service_reset
                TEQNE   r1,#&46                 ; see if service_modechange
                MOVNE   pc,r14
                LDR     r12,[r12]
                B       read_screen_size        ; ignore errors as these should never


myswi           LDR     R12,[R12]
                TEQ     R11,#Wimp_CreateWindow-Wimp_Initialise
                LDREQ   R10,[R1,#28]
                ORREQ   R10,R10,#(1 :SHL: 6)
                STREQ   R10,[R1,#28]
                TEQ     R11,#Wimp_OpenWindow-Wimp_Initialise
                LDRNE   PC,[R12,#4]
                LDR     R10,[R1,#4]     ;minx
                LDR     R11,screen_maxx
;                SUB     R11,R11,#40
                ADD     R10,R10,R11     ;max allowed maxx
                LDR     R11,[R1,#12]    ;maxx
                CMP     R10,R11
                STRLT   R10,[R1,#12]
                LDR     R10,[R1,#16]    ;maxy
                LDR     R11,screen_maxy
;                SUB     R11,R11,#80
                SUB     R10,R10,R11     ;min allowed miny
                LDR     R11,[R1,#8]    ;maxy
                CMP     R10,R11
                STRGT   R10,[R1,#8]
                MOV     R11,#Wimp_OpenWindow-Wimp_Initialise
                LDR     PC,[R12,#4]

read_screen_size
        STMFD   r13!,{r0-r3,r14}
        MVN     r0,#0                   ; read about current mode
        MOV     r1,#4                   ; r1 = XEigFactor
        SWI     XOS_ReadModeVariable
        LDMVSFD r13!,{r0-r3,pc}
        MOV     r3,r2
        MOV     r1,#11                  ; r1 = XWindLimit
        SWI     XOS_ReadModeVariable
        LDMVSFD r13!,{r0-r3,pc}
        MOV     r1,r2,LSL r3
        STR     r1,screen_maxx
        MOV     r1,#5                   ; r1 = YEigFactor
        SWI     XOS_ReadModeVariable
        LDMVSFD r13!,{r0-r3,pc}
        MOV     r3,r2
        MOV     r1,#12                  ; r1 = YWindLimit
        SWI     XOS_ReadModeVariable
        LDMVSFD r13!,{r0-r3,pc}
        MOV     r1,r2,LSL r3
        STR     r1,screen_maxy
        LDMFD   r13!,{r0-r3,pc}^              ; preserve flags

                END
